#!/bin/bash

echo "build image beginning"

BUILD_DIR=${WORKSPACE}/${MODULE}
if [ ! -d ${BUILD_DIR} ]; then
  echo "build image workspace not fount ${BUILD_DIR}"
  exit 1
fi

if [ ! -f ${BUILD_DIR}/Dockerfile ]; then
  echo "dockerfile not fount ${BUILD_DIR}/Dockerfile"
  exit 1
fi

VERSION=$(date +%y%m%d%H%M%s)
IMAGE_NAME=myhub.com/${JOB_NAME}/${MODULE}:${VERSION}
echo "${IMAGE_NAME}" > ${WORKSPACE}/IMAGE
echo "building image: ${IMAGE_NAME}"
docker build -t ${IMAGE_NAME} ${BUILD_DIR} || exit 1

echo "push image beginning"
docker push ${IMAGE_NAME} || exit 1
echo "push image finished"
